from django.shortcuts import render

# Create your views here.

from celery_tasks.sms.tasks import ccp_send_sms_code
import logging
logger = logging.getLogger('django')
import random
from django import http
from ihome.libs.yuntongxun.ccp_sms import CCP
from django.views import View
from django.http import HttpResponse
from django_redis import get_redis_connection
from ihome.libs.captcha.captcha import captcha

class ImageCodeView(View):
    '''返回图形验证码的类视图'''

    def get(self,request):

        cur = request.GET.get('cur')

        pre = request.GET.get('pre')

        # if pre:
        #
        #     pre = cur

        text, image = captcha.generate_captcha()

        redis_conn = get_redis_connection('verify_code')

        redis_conn.setex('img_%s' % cur, 300, text)

        return HttpResponse(image)